<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">


    <div class="form-group">
        <label class="col-xs-12 col-sm-2">店铺名称:</label>
        <div class="col-xs-12 col-sm-4">
           {if $row.super_play_no>0}<strong style="color:red">循环|</strong>{/if}
           {if $firstRelease==0}<strong style="color:red">首发|</strong>{/if}
           <span>{$shop.shop_name}</span>
           <a href="javascript:;" class="copy">   复制</a>
        </div>
        <label class="col-xs-12 col-sm-2">店铺地址:</label>
        <div class="col-xs-12 col-sm-4">
            <span>{$shop.address}</span><a href="javascript:;" class="copy">   复制</a>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">店铺二维码:</label>
        <div class="col-xs-12 col-sm-4">
            <a href="{$row.create_by}" target="_blank">
                <img src="{$row.create_by}" style="width: 100px;height: 100px;">
            </a>
        </div>
        <label class="col-xs-12 col-sm-2">活动平台:</label>
        <div class="col-xs-12 col-sm-4">
            {$shop.shop_type_text}
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">活动餐标:</label>
        <div class="col-xs-12 col-sm-4">
            {$back_money_text}
        </div>
        <label class="col-xs-12 col-sm-2">活动名额:</label>
        <div class="col-xs-12 col-sm-4">
            {$play_channel.quota}
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">活动方案:</label>
        <div class="col-xs-12 col-sm-4">
            {$row.scheme_no_text}
        </div>
        <label class="col-xs-12 col-sm-2">活动日期:</label>
        <div class="col-xs-12 col-sm-4">
            {$row.start_date}至{$row.end_date}
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">分发状态:</label>
        <div class="col-xs-12 col-sm-4">
            {$play_channel.status}
        </div>
        <label class="col-xs-12 col-sm-2">活动时间:</label>
        <div class="col-xs-12 col-sm-4">
            {$row.start_time_str}-{$row.end_time_str}
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">渠道活动状态:</label>
        <div class="col-xs-12 col-sm-4">
            {if $play_channel.activity_status=='活动发布'} 
            <span class="text-success">活动发布</span>
            {elseif $play_channel.activity_status=='活动结束' /}
            <span class="text-danger">活动结束</span>
            {elseif $play_channel.activity_status=='活动调整' /}
            <span class="text-info">活动调整</span>
            {/if}
        </div>
        <label class="col-xs-12 col-sm-2">渠道业务员:</label>
        <div class="col-xs-12 col-sm-4">
            {$play_channel.connector}
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">操作状态:</label>
        <div class="col-xs-12 col-sm-4">
            {$play_channel.operate_status}
        </div>
        <label class="col-xs-12 col-sm-2">更新时间:</label>
        <div class="col-xs-12 col-sm-4">
            {$row.update_dt}
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">下单限制:</label>
        <div class="col-xs-12 col-sm-4">
            {if $row.times_limit==1}
                每{$row.jt}天{$row.jc}次
            {else /}
                无限制
            {/if}
        </div>
        <label class="col-xs-12 col-sm-2">活动备注:</label>
        <div class="col-xs-12 col-sm-4">
            {$row.remarks}
        </div>
    </div>
    {if $play_channel.status=='无法分发' or $play_channel.status=='无法分发已处理'}
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">渠道无法分发备注:</label>
        <div class="col-xs-12 col-sm-4">
            {$play_channel.remark}
        </div>
    </div>
    {/if}
    {if $play_channel.status=='已结束' && $play_channel.activity_status=='活动结束'}
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">出单情况备注:</label>
        <div class="col-xs-12 col-sm-4">
            {$play_channel.remark}
        </div>
    </div>
    {/if}
    {if $row.play_status==2 && $play_channel.status=='未分发' && $play_channel.operate_status=='未处理'}
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">备注(无法分发时必填):</label>
        <div class="col-xs-12 col-sm-8">
            <textarea type="text" id="c-remark" class="form-control" name="row[remark]" cols="30" rows="5"></textarea>
        </div>
    </div>
    {/if}
    {if ($row.play_status==3 || $row.play_status==4 || $row.play_status==5) && $play_channel.activity_status=='活动结束' && $play_channel.operate_status=='未处理'}
    <div class="form-group">
        <label class="col-xs-12 col-sm-2">备注(出单情况):</label>
        <div class="col-xs-12 col-sm-8">
            <textarea type="text" id="c-remark" class="form-control" name="row[remark]" cols="30" rows="5"></textarea>
        </div>
    </div>
    {/if}
    <div class="form-group layer-footer">
        <label class="col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            {if $row.play_status==2 && $play_channel.status=='未分发' && $play_channel.operate_status=='未处理'}
            <input type="button" id="submit1" class="btn btn-success btn-embossed" value="已分发">
            <input type="button" id="submit2" class="btn btn-danger btn-embossed" value="无法分发">
            {/if}
            {if $row.play_status==2 && $play_channel.status=='已分发' && $play_channel.activity_status=='活动调整' && $play_channel.operate_status=='未处理'}
            <input type="button" id="submit3" class="btn btn-info btn-embossed" value="已调整">
            {/if}
            {if ($row.play_status==3 || $row.play_status==4 || $row.play_status==5) && $play_channel.operate_status=='未处理'}
            <input type="button" id="submit4" class="btn btn-primary btn-embossed" value="已结束">
            {/if}
        </div>
    </div>
</form>


<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
<script>
    window.onload = function(){
        var submit1 = document.getElementById("submit1");
        var submit2 = document.getElementById("submit2");
        var submit3 = document.getElementById("submit3");
        var submit4 = document.getElementById("submit4");
        var form = document.getElementById("edit-form");
        let isClicked = false;
        if (submit1!=undefined) {
            submit1.onclick = function(){
                if (isClicked) return; // 如果已点击，则直接返回，不执行后续代码
                isClicked = true; // 设置为已点击状态，防止连续点击触发多次执行
                // console.log('按钮被点击');
                // setTimeout(() => isClicked = false, 2000);
                var ids = "<?php echo $play_channel['id'] ?>"
                $.ajax({
                    url:"/hFtNsJROTk.php/channel/channel/agree",
                    data: {ids:ids},
                    success:function(result){
                        if (result.code==1) {
                            Toastr.success("操作成功")
                        } else {
                            alert("操作失败")
                        }
                        setTimeout(function () {
                            parent.layer.closeAll();
                            parent.$(".btn-refresh").trigger("click");
                        },1000)
                    }
                })
            }
        }
        if (submit2!=undefined) {
            submit2.onclick = function(){
                if (isClicked) return; // 如果已点击，则直接返回，不执行后续代码
                isClicked = true; // 设置为已点击状态，防止连续点击触发多次执行
                var ids = "<?php echo $play_channel['id'] ?>"
                var remark = $('#c-remark').val()
                if (!remark) {
                    Toastr.error("请填写备注")
                    return false
                }
                $.ajax({
                    url:"/hFtNsJROTk.php/channel/channel/refuse",
                    data: {ids:ids,remark:remark},
                    success:function(result){
                        if (result.code==1) {
                            Toastr.success("操作成功")
                        } else {
                            alert("操作失败")
                        }
                        setTimeout(function () {
                            parent.layer.closeAll();
                            parent.$(".btn-refresh").trigger("click");
                        },1000)
                    }
                })
            }
        }
        if (submit3!=undefined) {
            submit3.onclick = function(){
                if (isClicked) return; // 如果已点击，则直接返回，不执行后续代码
                isClicked = true; // 设置为已点击状态，防止连续点击触发多次执行
                var ids = "<?php echo $play_channel['id'] ?>"
                $.ajax({
                    url:"/hFtNsJROTk.php/channel/channel/adjust",
                    data: {ids:ids},
                    success:function(result){
                        if (result.code==1) {
                            Toastr.success("操作成功")
                        } else {
                            alert("操作失败")
                        }
                        setTimeout(function () {
                            parent.layer.closeAll();
                            parent.$(".btn-refresh").trigger("click");
                        },1000)
                    }
                })
            }
        }
        if (submit4!=undefined) {
            submit4.onclick = function(){
                if (isClicked) return; // 如果已点击，则直接返回，不执行后续代码
                isClicked = true; // 设置为已点击状态，防止连续点击触发多次执行
                var ids = "<?php echo $play_channel['id'] ?>"
                var remark = $('#c-remark').val()
                if (!remark) {
                    Toastr.error("请填写备注")
                    return false
                }
                $.ajax({
                    url:"/hFtNsJROTk.php/channel/channel/end",
                    data: {ids:ids,remark:remark},
                    success:function(result){
                        if (result.code==1) {
                            Toastr.success("操作成功")
                        } else {
                            alert("操作失败")
                        }
                        setTimeout(function () {
                            parent.layer.closeAll();
                            parent.$(".btn-refresh").trigger("click");
                        },1000)
                    }
                })
            }
        }
    }
    $('.copy').click(function (e) {
        var text = $(this).siblings('span').text();
        console.log(text)
        copyToClipboard_js(text)
        Toastr.success("复制成功")
    })
    function copyToClipboard_js(txt) {
        var temp = document.createElement("textarea"); //声明创建一个input元素
        document.body.appendChild(temp); //在body中追加input元素
        temp.value = txt; //把要复制的文字赋予input元素
        temp.select(); //选择要复制的文字
        document.execCommand("copy"); //把文字复制到剪贴板
        document.body.removeChild(temp); //移除body追加的input元素
    }
</script>
